﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Objects;
using BAL;

public partial class Admin_UCControls_UCPhuongThucThanhToan_Update : System.Web.UI.UserControl
{
    public static PhuongThucThanhToan ItemPhuongThucThanhToan;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ItemPhuongThucThanhToan = new PhuongThucThanhToan();
            ItemPhuongThucThanhToan = (PhuongThucThanhToan)Session["ItemPhuongThucThanhToan"];

            if (ItemPhuongThucThanhToan != null)
            {
                txtHinhThuc.Text = ItemPhuongThucThanhToan.HinhThuc.ToString();
                txtMoTa.Text = ItemPhuongThucThanhToan.GhiChu.ToString();
                txtDuongDan.Text = ItemPhuongThucThanhToan.DuongDan.ToString();
            }
        }
    }

    protected void btnLuu_Click(object sender, EventArgs e)
    {
        int item = 0;
        if (CheckNull())
        {
            if (ItemPhuongThucThanhToan == null)
            {
                item = BALPhuongThucThanhToan.Insert_PhuongThucThanhToan(txtHinhThuc.Text, txtMoTa.Text, txtDuongDan.Text, Common.Myconst.HOATDONG, 0);

            }
            else
            {
                item = BALPhuongThucThanhToan.Update_PhuongThucThanhToan(Int32.Parse(ItemPhuongThucThanhToan.Id.ToString()), txtHinhThuc.Text, txtMoTa.Text, txtDuongDan.Text, Common.Myconst.HOATDONG, Int32.Parse(ItemPhuongThucThanhToan.SapXep.ToString()));

            }
        }

        if (item > 0)
        {
            lblThongbao.Visible = true;
            lblThongbao.Text = "Cập nhật thành công";

        }
        else
        {
            lblThongbao.Visible = true;
            lblThongbao.Text = "Cập nhật thất bại";
        }
    }

    protected void btnQuaylai_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Admin/PhuongThucThanhToan.aspx");
    }

    public bool CheckNull()
    {
        bool flag = true;
        VisibleLable();

        if (txtHinhThuc.Text == "")
        {
            lblHinhThuc.Visible = true;
            txtHinhThuc.Focus();
            flag = false;
        }

        if (txtMoTa.Text == "")
        {
            lblMoTa.Visible = true;
            txtMoTa.Focus();
            flag = false;
        }

        return flag;
    }

    public void VisibleLable()
    {
        lblMoTa.Visible = false;
        lblHinhThuc.Visible = false;
    }
}
